package com.bobohost.crmrbac.web.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.bobohost.crmrbac.pojo.po.Department;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/thymeleaf")
@Slf4j
public class ThymeleafController {

    @GetMapping("/sayhi")
    public String sayHi(Model model){
        log.debug("--------------------------------------------------sayhi");
        //给model添加数据
        model.addAttribute("message", "Hello World");
        return "thymeleaf/01_hello";
    }
    //测试字符串
    @GetMapping("/str")
    public String str(Model model){
        //给model添加数据 --多个值可以写多个
        model.addAttribute("name", "Rose");
        model.addAttribute("age", 18);
        return "thymeleaf/02_str";
    }
    //测试javaBean
    @GetMapping("/javabean")
    public String javabean(Model model){
        //创建一个对象
        Department department =new Department(123,"KFB","开发部");

        model.addAttribute("department", department);

        return "thymeleaf/03_javabean";
    }
    @GetMapping("/list")
    public String list(Model model){
        //字符串列表
        List<String> strList =new ArrayList<>();
        strList.add("张三");
        strList.add("李四");
        strList.add("王五");

        //对象列表
        List<Department> departmentList =List.of(
                new Department(1001,"KFB","开发部"),
                new Department(1002,"CRW","财务部"),
                new Department(1003,"XZB","行政部")
        );


        model.addAttribute("strList", strList);
        model.addAttribute("departmentList", departmentList);

        return "thymeleaf/04_list";
    }

        @GetMapping("/map")
    public String map(Model model){
        Map<String,Object> map =Map.of(
                "name","Rose",
                "age",18,
                "memo","美女一枚"
        );

        model.addAttribute("map", map);

        return "thymeleaf/05_map";
    }
}
